#pragma once
#include <cmath>
#include <iostream>

using namespace std;

namespace U31
{
	class Root
	{
	public:

		Root()
		{
		}

		~Root()
		{
		}

		double Recursive(int y)
		{
			double x = 0;

			if (y == 1)
			{
				return 1;
			}
			else
			{
				x = (1 / sqrt(y) + Recursive(y - 1));
			}

			return x;
		}

		double Iterative(int y)
		{
			double x = 0;

			for (int i = 1; i < (y + 1); i++)
			{
				x = x + (1 / sqrt(i));
			}

			return x;
		}

		void main31()
		{
			//int x = 5;
			//cout << "Please give an integer: " << endl;
			//cin >> x;

			cout << ">>>>> Uppgift 3.1 <<<<<" << endl;
			cout << "Testing function with 5: " << endl;
			cout << "Recursive solution: " << Recursive(5) << endl;
			cout << "Iterative solution: " << Iterative(5) << endl << endl;
			cout << "Testing function with 12: " << endl;
			cout << "Recursive solution: " << Recursive(12) << endl;
			cout << "Iterative solution: " << Iterative(12) << endl << endl;

		}
	};
}

